package org.hhchat.leetcode.math;


/**
 * Created this one by HMH on 2017/10/2.
 *
 * Incrementing all but one is equivalent to decrementing that one. So let's do that instead. How many single-element decrements to make all equal? No point to decrementing below the current minimum, so how many single-element decrements to make all equal to the current minimum? Just take the difference from what we currently have (the sum) to what we want (n times the minimum).
 */
public class code453_easy {
    static class Solution {
        public int minMoves(int[] nums) {
            int n = nums.length;
            int sum = 0;
            int min = Integer.MAX_VALUE;
            for (int num : nums) {
                sum += num;
                min = Math.min(num, min);
            }
            return sum - n * min;
        }
    }

    public static void main(String[] args){

    }
}
